/**
 *
 * 全局工具
 *
 * file  : D_global.js
 * create: 2013-01-17
 * author: yangzheng@evmtv.com
 * update:
 *
 */

// CMS 助手类
var CmsHelper =
{
	isCssAttr: function( A )
	{
		var cssAttrs = '|left|top|width|height|fontSize|fontStyle|fontWeight|borderColor|borderWidth|borderStyle|textAlign|lineHeight|color|background|backgroundColor|backgroundAttachment|backgroundRepeat|backgroundImage|zIndex|';
		return cssAttrs.indexOf( '|' + A + '|' ) > -1;
	},
	
	isDimensionAttr: function( A )
	{
		var cssAttrs = '|left|top|width|height|fontSize|borderWidth|lineHeight|';
		return cssAttrs.indexOf( '|' + A + '|' ) > -1;
	},

	jsAttrToCssAttr: function( S, __pre )
	{
		__pre = ( __pre == undefined ? '-' : __pre );

		return S.replace( /[A-Z]/g, function(__s)
		{
			return __pre + __s.toLowerCase();
		});
	},

	CssToString: function( O )
	{
		var E = '';

		for( var i in O )
		{
			if( typeof O[i] == 'string' || typeof O[i] == 'number' )
			{
				if( this.isCssAttr( i ) && O[i] )
				{
					if( this.isDimensionAttr( i ))
						E += ( this.jsAttrToCssAttr(i) + ':' + O[i] + 'px' ) + ';'
					else if( i == 'backgroundImage' )
						E += ( this.jsAttrToCssAttr(i) + ':' + 'url(' + O[i] + ')' ) + ';'
					//else if( i == 'scrollAmount' || i == 'scrollDelay' )
					//	E += ( this.jsAttrToCssAttr(i, '') + ':' +  O[i] + ')' ) + ';'
					else
						E += ( this.jsAttrToCssAttr(i) + ':' + O[i] ) + ';'
				}
			}
		}

		E = E.trim(';');
		return E;
	}
}